package 比较器;

import java.util.Arrays;
import java.util.Comparator;

class Students{
    String mame;
    int age;
    int score;

    public Students(String mame, int age, int score) {
        this.mame = mame;
        this.age = age;
        this.score = score;
    }


    @Override
    public String toString() {
        return "Students{" +
                "mame='" + mame + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}

class AgeComparator implements Comparator<Students>{

    @Override
    public int compare(Students o1, Students o2) {

        return o1.age-o2.age;
    }
}



public class Test {

    public static void main(String[] args) {
        Students[] students=new Students[3];
        students[0] =new Students("aaa",18,16);
        students[1] =new Students("aaa",19,15);
        students[2] =new Students("aaa",20,14);
        AgeComparator ageComparator =new AgeComparator();
        Arrays.sort(students,ageComparator);
        System.out.println(Arrays.toString(students));


    }
    public static void main1(String[] args) {
        Students students1=new Students("张三",21,77);
        Students students2=new Students("李四",19,97);
        AgeComparator ageComparator =new AgeComparator();
        System.out.println(ageComparator.compare(students1, students2));
    }
}
